new Vue({
    el: '#app',
    data() {
        return {
            form: {
                SQLSerialNumber: "P_business_department_info",
                PaginationNumber: 1,//页数
                RowAmount: 10,//每页数据条数
                Department_Name: '',
                Condition: '',
                ProvinceNumber:'',
                Store_SerialNumber:'',
                CityNumber:'',
                CountyNumber:'',
                active: '',
                ExtensionCondition: '',
            },
            total: 0,
            tableData: [],	//表格数据
            treeData: [],
            isTree: true,
            defaultProps: {}
        }
    },
    mounted() {
        if (getCookie('role')) {
            let roleObj = JSON.parse(getCookie('role'));
            this.form.Store_SerialNumber = roleObj.other;
        }
        this.getData();
        this.getList(this.form);
    },
    methods: {
        onSerach() {			//查询方法
            this.form.PaginationNumber = 1;
            this.getList(this.form);
        },
        Add() {
            window.location.href = './add.html'
        },
        showTree() {

        },
        handleNode(row,node) {
            this.form.ProvinceNumber = '';
            this.form.CityNumber ='';
            this.form.CountyNumber ='';
            if (node.level==1) {
                this.form.ProvinceNumber = row.value;
            } else if(node.level==2){
                this.form.CityNumber = row.value;
            } else if (node.level==3){
                this.form.CountyNumber = row.value;
            }
            this.getList(this.form);
        },
        handleSizeChange(val) {
            this.form.PaginationNumber = 1;
            this.form.RowAmount = val;
            this.getList(this.form)
        },
        handleCurrentChange(val) {
            this.form.PaginationNumber = val;
            this.getList(this.form)
        },
        getData() {
            const that = this;
            $.ajax({
                url: `${BASE_URL1}/Address1`,
                type: 'GET',
                success: (res) => {
                    that.treeData = res
                },
            })
        },
        getList(form) {//换页方法
            const that = this
            let data = deepClone(form);
            let sql = " and business_department_info.Department_Name LIKE '%"+ data.Department_Name +"%'\r\n";
            if(data.ProvinceNumber){
                sql = sql + "and business_department_info.ProvinceNumber='"+ data.ProvinceNumber +"'\r\n";
            } 
            if(data.CityNumber){
                sql = sql + "and business_department_info.CityNumber='"+ data.CityNumber +"'\r\n";
            } 
            if(data.CountyNumber){
                sql = sql + "and business_department_info.CountyNumber='"+ data.CountyNumber +"'\r\n";
            }
            if (data.active=='1') {
                sql = sql + "and business_department_info.Store_SerialNumber='"+ data.Store_SerialNumber +"'\r\n";
            } else if (data.active=='2'){
                sql = sql + "and business_department_info.Store_SerialNumber=''\r\n";
            }
            data.ExtensionCondition = window.btoa(unescape(encodeURIComponent(sql)));
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
                type: 'POST',
                data,
                success: function (Result) {
                    that.tableData = Result.Rows;
                    that.total = Result.TotalRows;
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        Edit(Store_SerialNumber) {
            sessionStorage.setItem("Store_SerialNumber", Store_SerialNumber)
            window.location.href = './edit.html?Store_SerialNumber=' + Store_SerialNumber
        },
        Edit1(row, i) {
            const that = this
            this.$confirm(i == 0 ? '审核通过' : '审核未通过' + ', 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                let obj = deepClone(row);
                obj.Row_Status = i;
                $.ajax({
                    headers: requestHeaders(),
                    url: `${BASE_URL2}/generalBusiness/generalSave`,
                    type: 'POST',
                    data: {
                        Data: JSON.stringify({
                            Modify: { business_store_info: [obj] },
                        })
                    },
                    success: function (res) {
                        if (res.Status === 'success') {
                            that.$message({
                                type: 'success',
                                message: '操作成功!'
                            });
                            that.getList(that.form);
                        } else {
                            that.$message.error("操作失败，请稍后再试")
                        }
                    },
                    complete: function (XMLHttpRequest) {
                        that.loading = false
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json"
                })
            }).catch(() => { });
        },
        identify(row){            //去识别
            sessionStorage.setItem("Department_SerialNumber", row.Department_SerialNumber)
            window.location.href = './map.html?Department_SerialNumber=' + row.Department_SerialNumber;
        },
        Remove(row) {
            const that = this
            this.$confirm('警告！此操作将删除该店铺, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                let obj = deepClone(row);
                obj.Row_Status = '1';
                obj.Closed_Date = getYMDHMSDate();
                $.ajax({
                    headers: requestHeaders(),
                    url: `${BASE_URL2}/generalBusiness/generalSave`,
                    type: 'POST',
                    data: {
                        Data: JSON.stringify({
                            Modify: { business_store_info: [obj] },
                            Add: { base_operation_log: [generateLog('删除店铺信息', '平台端操作', 'business_store_info', JSON.stringify({ Modify: { business_store_info: [obj] } }))] }
                        })
                    },
                    success: function (res) {
                        if (res.Status === 'success') {
                            that.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            that.getList(that.form);
                        } else {
                            that.$message.error("删除失败，请稍后再试")
                        }
                    },
                    complete: function (XMLHttpRequest) {
                        that.loading = false
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json"
                })
            }).catch(() => { });
        }

    },
})